var table = layui.table;
$(document).ready(function() {
    //初始化数据列表
    load();
});

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return r[2];
    }else{
        if (!location.hash) return ''
        var regHash = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)");
        var rHash = location.hash.slice(1).match(regHash);
        return  rHash != null ?  rHash[2] : ''
    }
    return '';
}


function load() {
    table.render({
        id: 'news',
        elem: '#news',
        method: 'post',
        url:'/api/user/news',
        skin:'line',
        limit: 10, //每页默认显示的数量
        response: {
            statusCode: 200
        },
        where:{
            id:getQueryString("id")
        },
        cols: [[
            {field:'fileName', title: '信息标题',templet:function(row){
                return row.fileName+"."+row.suffix;
             }},
            {fixed: 'right', width: 190, align: 'center', unresize: true,templet:function(row){
                   var str='<div class="fr download_div_r" onclick="downloadFile(\''+row.id+'\')">'+
                    ' <img src="/images/download.png"><span>下载</span>'+
                    ' </div>'
                    return str;
            }}
        ]],
        done: function (res, curr, count) {
            $('.layui-table .layui-table-cell > span').css({'font-weight': 'bold'});//表头字体样式
            $('th').hide();//表头隐藏的样式
        },
        page: true
    });

    $("#searchBtn").click(search);
}


/**
 * 查询按钮
 */
function search() {
    table.reload('news', {
        page: {
            curr: 1
        },
        where: {title: $("#title").val(),conType:$("#conType").val(),
            status: $("#status").val(),createTime: $("#createTime").val(),beginDate:$("#beginDate").val(),
            endDate:$("#endDate").val(),dept:$("#dept").val(),createName:$("#createName").val()}
    });
}

/**
 * 下载按钮
 * @param obj
 */
function downloadFile(id) {
    window.location = "/api/pub/downFile/" + id;
}

